import requests
from pyquery import PyQuery as pq

# 定义URL
url1 = "https://bj.fang.com/quanwangso/search.html?city=bj&refer=sy_seach"

# 访问URL
response1 = requests.get(url1)
response1.encoding = 'gbk'  # 设置编码为gbk，因为fang.com使用的是gbk编码

# 使用pyquery解析HTML
doc1 = pq(response1.text)

# 抽取分类名称和网址
categories1 = []
for item in doc1('div.nav a').items():
    name = item.text()
    href = item.attr('href')
    categories1.append((name, href))

# 打印结果
print("URL 1:", url1)
for name, href in categories1:
    print(f"Name: {name}, URL: {href}")# 定义URL
url2 = "https://www.guazi.com/bj/buy/"

# 访问URL
response2 = requests.get(url2)

# 使用pyquery解析HTML
doc2 = pq(response2.text)

# 抽取分类名称和网址
categories2 = []
for item in doc2('div.category-list a').items():
    name = item.text()
    href = item.attr('href')
    categories2.append((name, href))

# 打印结果
print("\nURL 2:", url2)
for name, href in categories2:
    print(f"Name: {name}, URL: {href}")